package com.netcracker.studportal.server.model;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.json.simple.JSONObject;

@Entity
@Table(name = "Professors")
public class Professor implements Serializable {
	@Id
	@Column(name= "prof_id")
	private Long user_id;
	
	@Column(name= "first_name")
	private String prof_first_name;
	
	@Column(name= "patronymic")
	private String patronum_name;
	
	@Column(name= "last_name")
	private String prof_last_name;
	
	@Column(name= "birthday")
	private Date birthday;
	
	@ManyToOne
	@JoinColumn(name = "univ_id")
	private University univer;
	
	@Column(name="note")
	private String note;
		
	//getters
	
	public Long getId(){return this.user_id;}
	
	public String getFirst_name(){return this.prof_first_name;}
	
	public String getPatronymic(){return this.patronum_name;}
	
	public String getLast_name(){return this.prof_last_name;}
	
	public Date getBirthday(){return this.birthday;}
	
	public University getUniversity(){return this.univer;}
	
	public String getNote(){return this.note;}
	
	//setters
	
	public void setId(Long id){this.user_id=id;}
	
	public void setFirst_name(String first_name){this.prof_first_name=first_name;}
	
	public void setPatronymic(String patronum){this.patronum_name=patronum;}
	
	public void setLast_name(String last_name){this.prof_last_name=last_name;}
	
	public void setBirthday(Date birthday){this.birthday=birthday;}
	
	public void setUniversity(University univer){this.univer=univer;}
	
	public void setNote(String note){this.note=note;}
	
	public JSONObject kJSON(){
		JSONObject obj=new JSONObject();
		if(this.user_id!=null) obj.put("prof_id", this.user_id.toString());
		 obj.put("first_name", this.prof_first_name);
		 obj.put("patronymic", this.patronum_name);
		 obj.put("last_name", this.prof_last_name);
		 
		 if(this.birthday!=null){
			SimpleDateFormat format=new SimpleDateFormat("dd.MM.yyyy");		
			obj.put("birthday", format.format(this.birthday));
		 }
		 
		 obj.put("note", this.note);
		 
		if(this.univer!=null) {
			if(this.univer.getId()!=null) obj.put("univ_id", this.univer.getId().toString());	
			obj.put("univ_name", this.univer.getName());
			obj.put("city", this.univer.getCity());
		}
		return obj;		
	}
	
}
